<?php

namespace app\index\controller;
use think\Request;
use think\Controller;

class IndexController extends Controller {

    public function index() {
//        return $this->fetch();
    }

    public function test() {
        /**
        $t = new \my\Test();
        $t->t();
        import('my2/Test', EXTEND_PATH);
        $t2 = new \Test();
        $t2->t();
        dump(config());
        dump(url('index/blog/read?id=5'));
         * 
         */
        import('phpqrcode/phpqrcode',EXTEND_PATH);
        
        \QRcode::png("php"); 
        
        
    }
    
    public function test2(){
        echo '<img src="http://admin.0532888.co/index/index/test">';
    }

    public function decrypt()
    {
        if(Request::instance()->isAjax()){
            $name = input('post.name');
            $birthday = input('post.birthday');//;'1985-07-09'
            if(empty($name) || empty($birthday)){
                return $this->returnJson(0,-1,'不能为空',[]);
            }
            $checkDate = date('Ymd',strtotime($birthday));
            if( $checkDate !== $birthday){
                return $this->returnJson(0,-1,'输入的日期格式不正确',[]);
            }
            if($checkDate > date('Ymd',time())){
                return $this->returnJson(0,-1,'输入的日期大于了当前时间，不合法',[]);
            }
            $date = str_replace("","",$birthday);
            $data['name'] = $name;
            $data['num'] = $this->sumCount($date);
            return $this->returnJson(1,200,'成功',$data);
        }else{
            $this->view->engine->layout(false);
            return $this->fetch();
        }
    }

    public function sumCount($num){
        $arr = str_split($num);
        $sum = 0;
        foreach ($arr as $key => $value) {
            $sum += $value;
        }
        return ( $sum >=10 ) ? $this->sumCount($sum) : $sum;
    }

    /**
     * 返回json格式函数
     * $status 返回状态 1成功 0未成功
     * $errorCode 错误码 200 成功 400x 错误
     * $msg 返回信息
     * $data array 需要返回的数据 默认为空数组
     */
    function returnJson($status = 0,$errorCode = 4000,$msg='',$data=array()){
        $info = array(
            'status'=>$status,//状态值 0 未成功 1 成功
            'errorCode'=>$errorCode,
            'msg' => $msg,
            'data'=>$data
        );
        exit(json_encode($info));
    }

    public function one() {
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    public function two() {
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    public function three() {
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    public function four() {
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    public function five() {
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    public function six() {
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    public function seven() {
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    public function eight() {
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    public function nine() {
        $this->view->engine->layout(false);
        return $this->fetch();
    }

    public function qx(){
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    public function qxDetail(){
        $this->view->engine->layout(false);
        return $this->fetch();
    }

}
